# from rest_framework.renderers import JSONRenderer
from rest_framework_rapidjson.renderers import RapidJSONRenderer
from rest_framework.exceptions import ErrorDetail

class CustomJsonRenderer(RapidJSONRenderer):
    def render(self, data, accepted_media_type=None, renderer_context=None):
        code = 0

        if "detail" in data:
            if isinstance(data["detail"], ErrorDetail):
                code = 1

        data = {
            "code": code,
            "message": renderer_context["response"].status_text,
            "data": data
        }
        return super().render(data, accepted_media_type, renderer_context)